package com.joejag.mavenstats.client.views.main.reports;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.*;
import com.joejag.mavenstats.client.dto.ReportDTO;
import com.joejag.mavenstats.client.utils.ChartImage;

public class ReportView extends Composite
{
  private HTML body = new HTML();
  private VerticalPanel panel;
  private Image image;

  private ScrollPanel scroller = new ScrollPanel(body);

  public ReportView()
  {
    panel = new VerticalPanel();
    panel.add(scroller);
    panel.setSize("100%", "100%");
    panel.setCellHeight(scroller, "100%");
    scroller.setSize("100%", "100%");

    initWidget(panel);

    setStyleName("mail-Detail");

    body.setHTML("<h3>Report Stuff</h3>");
  }

  public void adjustSize(int windowWidth, int windowHeight)
  {
    int scrollWidth = windowWidth - scroller.getAbsoluteLeft() - 9;
    if (scrollWidth < 1)
      scrollWidth = 1;

    int scrollHeight = windowHeight - scroller.getAbsoluteTop() - 9;
    if (scrollHeight < 1)
      scrollHeight = 1;

    scroller.setSize("" + scrollWidth, "" + scrollHeight);
  }

  public void setReport(ReportDTO reportDTO)
  {
    body.setHTML("<h3>" + reportDTO.name + "</h3>");

    ChartImage chartImage = new ChartImage(reportDTO.name);
    addToReport(chartImage);

    HTML moreStuff = new HTML("<p>" + reportDTO.body + "<br />");
    addToReport(moreStuff);
  }

  private void addToReport(Widget chartImage)
  {
    DOM.appendChild(body.getElement(), chartImage.getElement());
  }

}